package com.llkj.common.util;

import java.lang.reflect.ParameterizedType;

/**
 * 类转换初始化
 */
public class TUtil {

    @SuppressWarnings("unchecked")
    public static <T> T getT(Object o, int i) {
        if (o.getClass().getGenericSuperclass() instanceof ParameterizedType &&
                ((ParameterizedType) o.getClass().getGenericSuperclass()).getActualTypeArguments().length > 0) {
            try {
                return ((Class<T>) ((ParameterizedType) (o.getClass()
                        .getGenericSuperclass())).getActualTypeArguments()[i])
                        .newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

}
